<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script type="text/javascript">
		var flag=false;
			var fun=function(){
				var img=document.querySelector("img")
				var h2=document.querySelector("h2")
				if(flag){
					img.setAttribute("src","img/off.png")
					h2.innerHTML="灯灭了"
					h2.setAttribute("style","color: black;")
					flag=false;					
				}
				else{
					img.setAttribute("src","img/on.png")
					h2.innerHTML="灯亮了"
					h2.setAttribute("style","color: red;")
					flag=true;					
				}
			}
		</script>
	</head>
	<body>
		<div onclick="fun()">
			<img src="img/off.png" width="100px" >
			<h2 style="color: black;">点击开灯</h2>
		</div>
	</body>
</html>
